package com.terrynoya.fight.data.parser.sff
{
	import com.terrynoya.fight.data.parser.sff.compress.RLE8;
	
	import flash.utils.ByteArray;
	import flash.utils.Endian;

	/**
	 * @author acer
	 */
	public class SFFSpriteNode
	{
		public var groupNo:int;
		public var itemNo:int;
		public var width:int;
		public var height:int;
		public var axisX:int;
		public var axisY:int;
		public var linkIndex:int;
		public var fmt:int;
		public var coldepth:int;
		public var offset:int;
		public var len:int;
		public var paletteIndex:int;
		public var flag:int;
		
		private var _data:ByteArray;
		
		public function SFFSpriteNode(bytes:ByteArray):void
		{
			bytes.endian = Endian.LITTLE_ENDIAN;
			
			groupNo = bytes.readUnsignedShort();
			itemNo = bytes.readUnsignedShort();
			width = bytes.readUnsignedShort();
			height = bytes.readUnsignedShort();
			axisX = bytes.readShort();
			axisY = bytes.readShort();
			linkIndex = bytes.readShort();
			fmt = bytes.readByte();
			coldepth = bytes.readByte();
			offset = bytes.readInt();
			len = bytes.readUnsignedInt();
			paletteIndex = bytes.readShort();
			flag = bytes.readShort();
		}

		public function get data() : ByteArray
		{
			return _data;
		}

		public function set data(data : ByteArray) : void
		{
			this._data = data;
		}
		
		public function decode(data:ByteArray):ByteArray
		{
			var rlt:ByteArray = data;
			switch(this.fmt)
			{
				case SFFSpriteDataFormat.LZ5:
				{
					break;
				}
				case SFFSpriteFormat.RAW:
				{
					break;
				}
				case SFFSpriteDataFormat.RLE8:
				{
					rlt = RLE8.decode(data);
					break;
				}
			}
			return rlt;
		}
		
		public function get id():String 
		{
			return this.groupNo + "" + this.itemNo;
		}
	}
}
